package priv.pront.code.national.acwing.search.bfs;

import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-05-23 19:28
 */
public class Acwing1100_抓住那头牛 {

    static int n, k, less = 0, more = 500010;
    static Queue<int[]> queue = new LinkedList<>();
    static int[] dx = {1, -1, 2};
    static boolean[] st;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        k = scanner.nextInt();
        st = new boolean[more];
        queue.add(new int[]{n, 0});
        while (!queue.isEmpty()) {
            int[] cur = queue.poll();
            if (cur[0] == k) {
                System.out.println(cur[1]);
                break;
            }
            for (int i = 0; i < 3; i++) {
                int nx;
                if (i == 2) {
                    nx = 2 * cur[0];
                } else {
                    nx = cur[0] + dx[i];
                }
                if (nx < less || nx >= more || st[nx]) continue;
                queue.add(new int[]{nx, cur[1] + 1});
                st[nx] = true;
            }
        }
    }
}
